function initPrompt() {
	$("#txtUrl").autocomplete({
		source: function(request, response) {
			$.ajax({
				url: "http://suggestqueries.google.com/complete/search",
				dataType: "jsonp",
				data: {
					hl: "en",
					client: "youtube",
					hjson: "t",
					ds: "yt",
					cp: "3",
					q: request.term
				},
				success: function(data) {
					response($.map(data[1], function(item) {
						return {label: item[0], value: item[0]}
					}));
				}
			});
		},
		minLength: 2,
		select: function(event, ui) {
			var contextPath = $("#contextPath").val();
			window.location= contextPath+'/search/' + ui.item.label;
		},
		open: function() { }
	});
};


function isYouTubeUrl(url) {
	if (url.indexOf("https://") == 0) {
		url = "http://" + url.substring(8);
	} else if (url.indexOf("http://") != 0) {
		url = "http://" + url;
	}

	url = url.replace("youtu.be/", "youtube.com/watch?v=");
	url = url.replace("http://youtube.com", "http://www.youtube.com");
	url = url.replace("http://m.youtube.com/", "http://www.youtube.com/");
	
	if (url.indexOf("http://www.youtube.com") != 0) {
		return false;
	}

	//url = url.replace("www.youtube.com", "youtube.com");

	if (url.indexOf("http://www.youtube.com/v/") == 0) {
		url = url.replace("www.youtube.com/v/", "www.youtube.com/watch?v=");
	} else if (url.indexOf("http://www.youtube.com/watch#") == 0) {
		url = url.replace("www.youtube.com/watch#", "www.youtube.com/watch?");
	}

	var main = "http://www.youtube.com/watch";
	if (url.indexOf(main) != 0) {
		return false;
	}

	var args = url.getArgs();
	if (args.v == undefined || args.v == "") {
		return false;
	}
	
	return true;
}

